/**
 * json配置举例，更多配置请看 IConfigSchema
 * @author luguoxiang
 * @date 2022/7/5
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
import { IConfigSchema, LgAutoComplete, LgBizSelect, LgBizSelectProps } from '@/soar';
import { getDict } from '@/api/common';
import { basePath } from './api';
import postTagApi, { basePath as tagBasePath } from '../postTag/api';
import { MenuComponent } from '@/types/interface';
import { basePath as roleBasePath } from '@/pages/system/auth/role/api';
import { basePath as orgBasePath } from '@/pages/system/auth/org/api';

const fieldList: IConfigSchema<any>[] = [
  {
    field: 'name',
    label: '名称',
    dataType: 'string',
    form: {
      rules: true, // true方式配置校验，必填
      component: LgAutoComplete,
      componentProps: {
        options: () => getDict('PostNameEnum'),
        valueField: 'label',
      },
    },
  },
  {
    field: 'alias',
    label: '别名(简称)',
    dataType: 'string',
  },
  {
    field: 'orgId',
    label: '所属组织',
    dataType: 'string',
    table: {
      colKey: 'orgIdName',
    },
    detail: {
      field: 'orgIdName',
    },
    form: {
      rules: true, // true方式配置校验，必填
      slots: 'orgId',
    },
  },
  {
    field: 'remark',
    label: '备注',
    dataType: 'string',
    form: {
      component: 't-textarea',
    },
  },
  {
    field: 'tagIds',
    label: '标签',
    table: false,
    search: false,
    form: {
      component: LgBizSelect,
      componentProps: {
        data: postTagApi.query,
        multiple: true,
      } as LgBizSelectProps,
    },
  },
];

export default fieldList;

/**
 * 组件配置（用于生成菜单数据）
 */
export const COMPONENTS: MenuComponent[] = [
  {
    title: '职位管理',
    component: () => import('./List.vue'),
    sort: 30,
    keepalive: true,
    icon: 'layers',
    permits: [`GET${basePath}/query`, `GET${tagBasePath}/query`, `GET${orgBasePath}/query`],
    elements: [
      { title: '新增', code: 'create', permits: [`POST/${basePath}/create`] },
      { title: '更新', code: 'update', permits: [`POST/${basePath}/update`] },
      { title: '删除', code: 'remove', permits: [`POST/${basePath}/remove`] },
      { title: '详情', code: 'detail', permits: [`GET${basePath}/detail`] },
      { title: '导入', code: 'import', permits: [`POST/${basePath}/import`] },
      { title: '导出', code: 'export', permits: [`GET${basePath}/export`] },
      { title: '清除缓存', code: 'clear-cache', permits: [`POST${basePath}/clear-cache`] },
      {
        title: '分配角色',
        code: 'role',
        permits: [`POST${basePath}/set-role-ids`, `GET${basePath}/get-role-ids`, `GET${roleBasePath}/query`],
      },
    ],
  },
];
